﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

public partial class timViec : System.Web.UI.Page
{
    VLGDataContext _db = new VLGDataContext();
    CommonPage _cmp = new CommonPage();
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["currentItem"] = "";      
        if (!IsPostBack)
        {
            Page.Title = "Vieclamgap.net | Trang cá nhân | Quản lý đăng tin tìm người làm theo yêu cầu trên Vieclamgap.net";
            try
            {
                if (String.IsNullOrEmpty(Session["KhachHang"].ToString()))
                {
                    Response.Redirect(ResolveClientUrl("warnLogin.aspx"));
                }
                else
                {
                    loadDrop();
                }
            }
            catch { Response.Redirect(ResolveClientUrl("Default.aspx")); }
        }
    }
    void loadDrop()
    {
        var CateItems = from ct in _db.Categories
                        where ct.AnHien == true
                        select ct;
        dropCate.DataSource = CateItems;
        dropCate.DataTextField = "TenCate";
        dropCate.DataValueField = "idCategory";
        dropCate.DataBind();
        // Load du lieu vao Repeater
        try
        {
            var gigRqItem = from gigrq in _db.GigRequests
                            where _cmp.Customer.idAcc == gigrq.idAcc
                            select gigrq;
            rpt.DataSource = gigRqItem;
            rpt.DataBind();
        }
        catch { }
    }
    [WebMethod]
    public static int AddGigRequest(string required)
    {
        if (!string.IsNullOrEmpty(required))
        {
            try
            {
                VLGDataContext _db = new VLGDataContext();
                CommonPage cm = new CommonPage();
                var gigRequest = new GigRequest();
                gigRequest.Required = required;
                gigRequest.TimeInput = DateTime.Now;
                gigRequest.idAcc = cm.Customer.idAcc;
                _db.GigRequests.InsertOnSubmit(gigRequest);
                _db.SubmitChanges();
                return gigRequest.id;
            }
            catch
            {
                return 0;
            }
        }
        else
            return 0;
    }
    [WebMethod]
    public static int DeleteGigRequest(string id)
    {
        if (!string.IsNullOrEmpty(id))
        {
            try
            {
                VLGDataContext _db = new VLGDataContext();
                CommonPage cm = new CommonPage();
                var gigRequest = (from g in _db.GigRequests
                                  where g.id == Convert.ToInt32(id)
                                  select g).Single();
                _db.GigRequests.DeleteOnSubmit(gigRequest);
                _db.SubmitChanges();
                return 1;
            }
            catch
            {
                return 0;
            }
        }
        else
            return 0;
    }
}